/**
 * Various kinds of display modes extend from this class
 * @author Rex, David
 */

package view;

import java.awt.Color;
import model.Table;
import org.jfree.chart.ChartPanel;

/**
 * abstract class of display modes
 * @author Rex, David
 *
 */
public abstract class GeneralDisplayMode {
    private final int myPanelWidth = 500;
    private final int myPanelHeight = 270;

    private int myDataSize;
    private int mySortIndex;
    private Table myTable;
    private String[] myCategoryNames;

    /**
     * construct a display mode
     * @param dataTable sub-table of data
     * @param categoryNames categories to be displayed
     */
    public GeneralDisplayMode(Table dataTable, String[] categoryNames) {
        myTable = dataTable;
        myCategoryNames = categoryNames;
        if (dataTable != null) {
            myDataSize = dataTable.getDataSize();
        }
    }

    /**
     * return categories to be displayed
     * @return
     */
    public String[] getCategoryNames() {
        return myCategoryNames;
    }

    /**
     * return the dataTable (a sub-table given by DataLoader)
     * @return
     */
    public Table getTable() {
        return myTable;
    }

    /**
     * get the number of data sets
     * @return number of data sets
     */
    public int getDataSize() {
        return myDataSize;
    }

    /**
     * plot Graph
     * @return a Panel on which the graph is plotted
     */
    public ChartPanel makeGraph() {
        ChartPanel panel = constructChartPanel();
        setDefaultSize(panel);
        panel.setFocusable(true);
        panel.setAutoscrolls(true);
        panel.setBackground(Color.PINK);
        return panel;
    }

    /**
     * construct ChartPanel
     * @return ChartPanel
     */
    public abstract ChartPanel constructChartPanel();

    /**
     * sort in ascending order
     */
    public abstract void sortAscending();

    /**
     * sort in descending order
     */
    public abstract void sortDescending();

    protected void setDefaultSize (ChartPanel panel) {
        panel.setSize(myPanelWidth, myPanelHeight);
    }

    protected int getSortIndex() {
        return mySortIndex;
    }

    protected void setSortIndex(int index) {
        mySortIndex = index;
    }
}
